package logic

import (
	"context"
	"knowledge/knowledgerpc/knowledgerpc"

	"knowledge/api/internal/svc"
	"knowledge/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddknowledgeLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddknowledgeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddknowledgeLogic {
	return &AddknowledgeLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddknowledgeLogic) Addknowledge(req *types.AddknowledgeRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	knowledge, err := l.svcCtx.KnowledgeRpc.AddKnowledge(l.ctx, &knowledgerpc.AddKnowledgeRequest{
		Title: req.Title,
		Click: int64(req.Click),
		State: req.State,
	})
	if err != nil {
		return &types.Response{
			Message: "添加失败",
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "添加成功",
		Code:    200,
		Data:    knowledge,
	}, nil
}
